<?php
	$head->_template_assign("TITEL",(string)$language->titles->value_3);
	$template->_template_read("./System/Design/Templates/log_show.html");
	
	// Grundlegende Sprach-Strings-Einsetzen
	$template->_template_assign("CAPTION_LOG1", (string)$language->common->value_16);
	$template->_template_assign("CAPTION_LOG2", (string)$language->common->value_17);
	$template->_template_assign("CAPTION_LOG3", (string)$language->buttons->value_5);
	$template->_template_assign("CAPTION_LOG4", (string)$language->common->value_18);
	$template->_template_assign("CAPTION_LOG5", (string)$language->common->value_19);
	$template->_template_assign("CAPTION_LOG6", (string)$language->common->value_20);
	$template->_template_assign("CAPTION_LOG7", (string)$language->common->value_21);
	
	if (!isset($_POST["file"]) AND $_POST["file"] != "nil"){
		$today = "./Logs/".date("d-m-y", time()).".log";
	} else {
		$today = $_POST["file"];
	}
	$handle = opendir("./Logs/");
	$logs = array();
	while ($file = readdir ($handle)) {
		if($file != "." AND $file != ".." AND substr($file, -4) == ".log"){
			$logs["FILE"] = "./Logs/".$file;
			$template->_template_append("AVAILABLE_LOGS", $logs);
		}
		
	}	
	
	if (count($logs) == 0){
		$head->_template_assign("ERROR",(string)$language->errors->value_5);
		$included = true;
		include("System/Kernel/Includes/index.include.php");
	} else {
		
		if (!file_exists($today)){
			$today = $logs["FILE"];
		}
		$log = sqlite_open($today);
		$array = sqlite_array_query($log, "SELECT * FROM log ORDER BY id DESC", SQLITE_ASSOC);
		$bg_color = 1;
		foreach ($array as $entry){
			if ($bg_color == 1){
				$entrys["BG_COLOR"] = "#dedede";
				$bg_color++;
			} else {
				$entrys["BG_COLOR"] = "#efefef";
				$bg_color = 1;
			}
			$entrys["TIME"] = date("d.m.y H:i", $entry['date']);
			$entrys["TYPE"] = $entry['type'];
			$entrys["MSG"] = $entry['msg'];
			$entrys["APP"] = $entry['app'];
			$template->_template_append("ENTRYS", $entrys);
		}
		sqlite_close($log);
		$template->_template_append("CURRENT", $today);
	}
?>